#include "xlcd.h"
#include "delay.h"

/*********************************************************************
Function Name:             BusyXLCD
Description:               This function returns the busy status
                           of the LCD Controller.The Busy flag is
                           is MS bit when the Instruction Reg is read
Input parameters:          none
Return value:              char- returns 1 if Busy flag is set, else 0
*********************************************************************/

char BusyXLCD(void)
{
    char status;
    /* Configure all pins as input */
    TRIS_DATA_PIN_7 = 1;
    TRIS_DATA_PIN_6 = 1;
    TRIS_DATA_PIN_5 = 1;
    TRIS_DATA_PIN_4 = 1;

    RS_PIN = 0;           /* for selecting AC for read */
    RW_PIN = 1;           /* for read operation */

    E_PIN = 1;

    /* delay for data out */
    DelayDBOutput();

    /* read the busy bit */
    if(READ_PIN_7)        /* busy flag */
    {
        status = 1;
    }
    else
    {
        status = 0;
    }
    
    DelayEPulseWidthHigh();
    E_PIN = 0; /* Reset clock line */

    /* Clock out other nibble*/

    DelayEPulseWidthLow();
    E_PIN = 1;
    DelayEPulseWidthHigh();
    E_PIN = 0;	/* Reset control line */

    RW_PIN = 0;

    return status;
} /* end of function */
